package com.ncui.wisdomLearn.config;

import cn.dev33.satoken.stp.StpInterface;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ncui.wisdomLearn.api.entity.Role;
import com.ncui.wisdomLearn.api.entity.UserRole;
import com.ncui.wisdomLearn.biz.user.service.RoleService;
import com.ncui.wisdomLearn.biz.user.service.UserRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Lvlele
 * @since 2025/1/3 10:53
 */
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final RoleService roleService;
    private final UserRoleService userRoleService;


    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return List.of();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<UserRole> roles = userRoleService.list(Wrappers.<UserRole>lambdaQuery()
                .eq(UserRole::getUserId, loginId));

        List<Long> roleIds = roles.stream().map(UserRole::getRoleId).toList();

        List<Role> roleList = roleService.listByIds(roleIds);
        return roleList.stream().map(Role::getRoleName).toList();
    }
}
